package com.totoro.domain.key;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.totoro.domain.Project;
import com.totoro.domain.Tutor;

//评阅论文主键实体类
@Embeddable
public class ReviewProjectKey implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "reviewer_id", referencedColumnName = "id")
	private Tutor reviewer;// 评阅人
	/**
	 * @generated
	 */
	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "project_id", referencedColumnName = "id")
	private Project project;// 毕业设计

	// 空构造器
	public ReviewProjectKey() {
	}

	public Tutor getReviewer() {
		return reviewer;
	}

	public void setReviewer(Tutor reviewer) {
		this.reviewer = reviewer;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	// 复写hashCode方法
	@Override
	public int hashCode() {
		return getReviewer().getId() * 13 + getProject().getId();
	}

	// 复写equals方法
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj != null && this.getClass() == obj.getClass()) {
			ReviewProjectKey target = (ReviewProjectKey) obj;
			if (getReviewer().getId().equals(target.getReviewer().getId())
					&& getProject().getId().equals(target.getProject().getId()))
				return true;
		}
		return false;
	}

}
